package com.pucong.gitee.database.backup.configuration.exception;

import com.pucong.gitee.database.backup.utils.ApplicationContextUtil;
import org.apache.commons.lang3.StringUtils;


/**
 * 自定义异常类
 */
public class BusinessException extends RuntimeException {

    private static BusinessExceptionService businessExceptionService;

    /**
     * 根据异常提示，返回异常信息
     * @param code
     */
    public BusinessException(String code, String... args) {
        super(getBusinessExceptionMessage(code,args));
    }

    public static String getBusinessExceptionMessage(String code,String... args) {
        if(businessExceptionService == null){
            businessExceptionService = (BusinessExceptionService) ApplicationContextUtil.getBean(BusinessExceptionService.class);
        }
        String msg = businessExceptionService.getMessage(code,args);
        return StringUtils.isBlank(msg) ? code : msg;
    }
}
